package com.itheima.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/*
* controller方法常用的返回值类型
* */
@Controller
@RequestMapping("jsp")

public class JspController {

    //1.String
    @RequestMapping("str")
    public String testStr(){
        System.out.println("str");
        return "index";
    }
    //2.ModelAndView
    @RequestMapping("mv")
    public ModelAndView testMv(ModelAndView mv){
        //ModelAndView mv = new ModelAndView();

        //携带数据
        mv.addObject("username","吕布");
        mv.setViewName("index");
        System.out.println(mv);
        return mv;
    }

    //3.void
    @RequestMapping("testVoid")
    /*
    @GetMapping:接收get请求
    @PostMapping:接收post请求
    @DeleteMapping:接收delete请求
    @PutMapping:接收put请求
    */
    public void testVoid(HttpServletRequest request,HttpServletResponse response) throws Exception {
        System.out.println("void...");
        //原生servlet  API
        request.getRequestDispatcher("index.jsp").forward(request,response);
        //response.sendRedirect(request.getContextPath()+"/index.jsp");
    }
}
